$('document').ready(function () {

    jQuery(".slideTxtBox").slide({mainCell:".bd ul",autoPlay:true,effect:"leftMarquee",vis:6,interTime:25,trigger:"click"});


    //获取网易验证




    var Request = new searchUrl(),
        form=Request.form;


    if(form=='register'){
        $('.loginBox').hide();
        $('.registerBox').show();
    }


    getSettingPicToken();


    //切换普通登录
    $('#puLogin').click(function () {

    let this_=$(this);
    this_.addClass('clickSpan');
    $('#codeLogin').removeClass('clickSpan');
    $('.puLoginBox').show();
    $('.cordLoginPart').hide();

});



    //验证码登入
    $('#codeLogin').click(function () {

        let this_=$(this);
        this_.addClass('clickSpan');
        $('#puLogin').removeClass('clickSpan');
        $('.puLoginBox').hide();
        $('.cordLoginPart').show();

    });



    //密码登录
    //密码登录
    //密码登录
    //密码登录
    //密码登录




    $('#normalPassword').focus(function () {
        let a = $("#normalPhone").val();

        if(isNull(a)){
            defaultHint("请输入手机号码")
        }else{
            if(!verifyTel(a)){
                defaultHint('请输入正确的手机号码')
            }
        }

    });



    $('#normal').click(function () {
        var a = $("#normalPhone").val(),
            b = $('#normalPassword').val(),
            typone = verifyTel(a),
            typtwo = checkPass(b);


        if(isNull(a)){
            defaultHint("请输入手机号码");
            return
        }

        if(isNull(b)){
            defaultHint("请输入密码");
            return
        }
        if(!typone){
            defaultHint("手机号码错误");
            return
        }
        if(!typtwo){
            defaultHint("账号或者密码有误");
            return
        }


        b = hex_md5(b);

        var code='';
        //定位使用用户修改的定位；

        if(notNull(sessionStorage.getItem('userChooseLocationCode'))){
            code = sessionStorage.getItem('userChooseLocationCode');

        }else {
             code = sessionStorage.getItem('autoLocationCode');

        }

        myAjaxFunc({
            url: geturluser + "normalLogin",
            type: 'post',
            dataType: 'json',
            data: {username: a, password: b, currentCityCode: code, platform: 'pc/'+getPlatform()},
            mySuccess: function (data) {
                if (data.success) {

                    localStorage.setItem('pctoken', Base64.encode(data.data.token));

                    setUserInfo(data.data.user);


                    let time = new Date();        //获取当前日(1-31)

                    localStorage.setItem('time', time.getDate());

                    alert('登录成功');

                } else {
                    if (notNull(data.msg)) {
                        defaultHint(data.msg);
                    } else {
                        defaultHint('密码错误');


                    }

                }
            }

        })

    });


    //验证码登录
    //验证码登录
    //验证码登录
    //验证码登录
    //验证码登录

    /*动态验证码登录发送验证码60S*/



    var getPicToken = '';

    var getLoginCode=$("#getCode");

    var flagloginwangyiCode=false;




    //智能无感验证
    function getLoginwangyiCode(){

        let picTokenAppId_=sessionStorage.getItem('picTokenAppId');


        if (notNull( picTokenAppId_)) {

            var serviceProvider =  picTokenAppId_.split(',');
            var service = serviceProvider[0];
            var appid_capthaid = serviceProvider[1];

            /*网易无感*/
            if (service == 'wangyi') {


                initNECaptcha({
                    captchaId: appid_capthaid,
                    element: '#wangyiCode',
                    mode: 'float',
                    width: 320,
                    onReady:function (instance) {
                        // 初始化成功
                        $('.yidun_intelli-text').text('点击获取验证码').css({'line-height':"46px",'color':'#ff6f6e'});
                        $('.yidun_intelli-control').css({
                            height:'48px',
                        });
                        flagloginwangyiCode=true;
                    },
                    onVerify: function (err, data) {

                        if (!err) {
                            getPicToken = data.validate;
                            getpicTokenMessageCode( getPicToken, service);

                            flagloginwangyiCode=false;

                        }
                    }
                },  function onerror(err) {
                    console.log(err)
                    // 验证码初始化失败处理逻辑，例如：提示用户点击按钮重新初始化
                });


            }

        }
        else {
            getLoginCode.show().removeClass('getCodeHui');
            $('#wangyiCode').hide();

        }

    }

    getLoginwangyiCode();

    var loginTimeList;
    //倒计时
    function Countdown() {
        getLoginCode.show();
        $('#wangyiCode').hide();

        clearInterval(loginTimeList);
        getLoginCode.addClass('getCodeHui');

        var i = 60;
        loginTimeList = setInterval(function () {
            i--;
            getLoginCode.text("" + i + "S后重发");
            if (i < 0) {
                clearInterval(loginTimeList);
                getLoginwangyiCode();
                getLoginCode.text("获取验证码");
                getLoginCode.removeClass('getCodeHui');

                getLoginCode.hide();

                $('#wangyiCode').show();


            }
        }, 1000);

    }

    //获取验证码

    function getpicTokenMessageCode( getPicToken, service) {


        let telNumber = $("#codePhone").val();

        if(verifyTel(telNumber)) {

            myAjaxFunc({
                url: geturluser + "getIdentifyCode",
                type: "post",
                dataType: 'json',
                data: {phone: telNumber, picToken: getPicToken, serviceProvider: service},
                mySuccess: function (data) {
                    if (data.success) {

                        $('#phoneCode').focus();
                        if (data.msg == null) {
                            defaultHint('发送成功，请注意短信消息')
                        } else {
                            defaultHint(data.msg)
                        }

                    } else {
                        if (data.msg == null) {
                            defaultHint('发送失败')
                        } else {
                            defaultHint(data.msg)

                        }
                    }

                    //开始倒计时
                    Countdown();
                }
            });
        }else {
            defaultHint('请输入正确的手机号码')
        }
    }


    //手机号码验证 ——通过执行无感智能验证
    $('#codePhone').bind('input propertychange', function () {
        let telNumber = $("#codePhone").val();
        if (telNumber.length >= 11) {
            if (verifyTel(telNumber)) {


                if(!flagloginwangyiCode){
                    getLoginwangyiCode()
                }

                getLoginCode.hide();

                $('#wangyiCode').show();


            } else {

                defaultHint('请输入正确的手机号码');

                getLoginCode.show();
                $('#wangyiCode').hide();
                clearInterval(loginTimeList);
                getLoginCode.text("获取验证码");
                getLoginCode.removeClass('getCodeHui');

            }

        }else {
            getLoginCode.show();
            $('#wangyiCode').hide();
            clearInterval(loginTimeList);

            getLoginCode.text("获取验证码");
            getLoginCode.removeClass('getCodeHui');


        }

    });

    //失焦验证手机号码
    getLoginCode.click(function () {
        var telNumber = $("#codePhone").val(), typ = verifyTel(telNumber);
        if (typ) {
            getLoginwangyiCode()
        } else {

            defaultHint('请输入正确的手机号码')

        }
    });

    $('#codeEnt').click(function () {
        var telNumber = $("#codePhone").val(),
            checkCode = $("#phoneCode").val(),
            typone = verifyTel(telNumber);

        if(isNull(telNumber)){
            defaultHint("请输入手机号码");
            return
        }


        if(isNull(checkCode)){
            defaultHint("请输入验证码");
            return
        }

        if(!typone){
            defaultHint("手机号码错误");
            return
        }

        var code='';
        //定位使用用户修改的定位；

        if(notNull(sessionStorage.getItem('userChooseLocationCode'))){
            code = sessionStorage.getItem('userChooseLocationCode');

        }else {
            code = sessionStorage.getItem('autoLocationCode');

        }

        myAjaxFunc({
            url: geturluser + "phoneLogin",
            type: "post",
            dataType: 'json',
            data: {phone: telNumber, identifyCode: checkCode, currentCityCode: code, platform:'pc/'+getPlatform()},
            mySuccess: function (data) {
                if (data.success) {
                    localStorage.setItem('pctoken', Base64.encode(data.data.token));

                    setUserInfo(data.data.user);
                    var time = new Date();        //获取当前日(1-31)
                    localStorage.setItem('time', time.getDate());

                    alert('登录成功');

                } else {
                    if (data.msg == null) {
                        defaultHint('验证码失效');
                    } else {
                        defaultHint( data.msg);

                    }
                }
            }
        });



    });




    //注册
    //注册
    //注册
    //注册
    //注册



    $('#register').click(function () {

        $('.loginBox').hide();
        $('.registerBox').show();

    });


    $('#getLogin').click(function () {

        $('.loginBox').show();
        $('.registerBox').hide();

    });

  var  getRegisterCode=$('#getRegisterCode');


    var flagRegisterwangyiCode=false;



    //手机号码验证 ——通过执行无感智能验证
    $('#registerPhone').bind('input propertychange', function () {
        let telNumber = $("#registerPhone").val();
        if (telNumber.length >= 11) {
            if (verifyTel(telNumber)) {
                if(!flagRegisterwangyiCode){
                    getwangyiRegisterCode()

                }

                getRegisterCode.hide();
                $('#registerwangyicode').show();

            } else {

                defaultHint('请输入正确的手机号码');

                getRegisterCode.show();
                $('#registerwangyicode').hide();

                clearInterval(timeListRegister);

                getRegisterCode.text("获取验证码");
                getRegisterCode.removeClass('getCodeHui');


            }

        }else {
            getRegisterCode.show();
            $('#registerwangyicode').hide();

            clearInterval(timeListRegister);
            getRegisterCode.text("获取验证码");
            getRegisterCode.removeClass('getCodeHui');


        }

    });


    getRegisterCode.click(function () {
        var telNumber = $("#registerPhone").val(), typ = verifyTel(telNumber);
        if (typ) {
            getwangyiRegisterCode()
        } else {

            defaultHint('请输入正确的手机号码')

        }
    });


    //智能无感验证
    function getwangyiRegisterCode(){

        var picTokenAppId_=sessionStorage.getItem('picTokenAppId');

        if (notNull(picTokenAppId_)) {

            var serviceProvider = picTokenAppId_.split(',');
            var service = serviceProvider[0];
            var appid_capthaid = serviceProvider[1];


            /*网易无感*/
            if (service == 'wangyi') {

                initNECaptcha({
                    captchaId: appid_capthaid,
                    element: '#registerwangyicode',
                    mode: 'float',
                    width: 320,
                    onReady:function (instance) {
                        // 初始化成功

                        $('.yidun_intelli-text').text('点击获取验证码').css({'line-height':"46px",'color':'#ff6f6e'});
                        $('.yidun_intelli-control').css({
                            height:'48px',
                        });

                        flagRegisterwangyiCode=true;

                    },
                    onVerify: function (err, data) {
                        if (!err) {
                            getPicToken = data.validate;

                            register_getpicTokenMessageCode( getPicToken, service);
                            flagRegisterwangyiCode=false;
                        }
                    }
                },  function onerror(err) {
                    console.log(err)

                });


            }

        }
        else {

            getRegisterCode.removeAttr('disabled').removeClass('sendBg');
            getRegisterCode.show();


        }

    }

    getwangyiRegisterCode();


    var timeListRegister;
    //倒计时
    function CountdownRegister() {

        getRegisterCode.show();

        $('#registerwangyicode').hide();

        clearInterval(timeListRegister);

        getRegisterCode.attr('disabled', 'disabled').addClass('getCodeHui');

        var i = 60;
        timeListRegister = setInterval(function () {
            i--;
            getRegisterCode.text("" + i + "S后重发");
            if (i < 0) {
                clearInterval(timeListRegister);
                getwangyiRegisterCode();

                getRegisterCode.text("获取验证码");
                getRegisterCode.hide();

                $('#registerwangyicode').show();

                getLoginCode.removeClass('getCodeHui').removeAttr('disabled');

            }
        }, 1000);


    }


    //获取验证码
    function register_getpicTokenMessageCode( getPicToken, service) {


        let registerPhone = $('#registerPhone').val();

        if(verifyTel(registerPhone)) {

            myAjaxFunc({
                url: geturluser + "getIdentifyCodeInRegister",
                type: "post",
                dataType: 'json',
                data: {phone: registerPhone, picToken: getPicToken, serviceProvider: service},
                mySuccess: function (data) {


                    if (data.success) {

                        if (data.msg == null) {
                            defaultHint('发送成功，请注意短信消息')
                        } else {
                            defaultHint(data.msg)
                        }

                    } else {

                        if (data.msg == null) {
                            defaultHint('发送失败')
                        } else {

                            defaultHint(data.msg);

                            var dataMsg = data.msg.indexOf('已被注册');

                            if (dataMsg == '-1') {
                            } else {
                                setTimeout(function () {
                                    //到验证码登录

                                    $('.loginBox').show();
                                    $('.registerBox').hide();

                                    $(".loginTypeTwo").show();
                                    $(".loginTypeOne").hide();

                                    $('#codePhone').val(registerPhone);
                                    $('#normalPhone').val(registerPhone);

                                    setTimeout(function () {
                                        getLoginwangyiCode();
                                    }, 300);


                                }, 1000);
                            }
                        }
                    }
                    //开始倒计时
                    CountdownRegister();
                }
            });
        }else {
            defaultHint('请输入正确的手机号码')
        }
    }


    /*注册下一步*/
    $('#registerNext').click(function () {
        var telNumber = $("#registerPhone").val(),
            checkCode = $("#registerCode").val();
        var typone = verifyTel(telNumber);


        if(isNull(telNumber)){
            defaultHint("请输入手机号码");
            return
        }


        if(isNull(checkCode)){
            defaultHint("请输入验证码");
            return
        }

        if(!typone){
            defaultHint("手机号码错误");
            return
        }
        myAjaxFunc({
            url: geturluser + "isIdentifyCodeSuccess",
            type: "post",
            dataType: 'json',
            data: {phone: telNumber, identifyCode: checkCode},
            mySuccess: function (data) {
                if (data.success) {

                    localStorage.setItem('pctoken', Base64.encode(data.data.token));

                    setUserInfo(data.data.user);

                    var time = new Date();        //获取当前日(1-31)
                    localStorage.setItem('time', time.getDate());

                    // setTimeout(function () {
                    //     window.location.href = 'setLogin.html?settype=register'
                    // }, 100)

                  $('.passBox').show()
                  $('.registerBox').hide()




                } else {
                    if (data.msg == null) {
                        defaultHint('验证码失效');
                    } else {
                        defaultHint(data.msg);

                    }


                }
            }
        });




    });






//保存密码


    $("#passWordCom").click(function(){

        var pone=$('#password').val(),
            ptwo=$('#password1').val(),
            typone=checkPass(pone),
            typtwo=checkPass(ptwo),
            userInfo=getUserInfo(),
            aircraftphone=userInfo.phone ;


        if(isNull(typone)){
            defaultHint("请输入密码");
            return
        }


        if(isNull(typtwo)){
            defaultHint("请再次输入密码");
            return
        }


        if(!typone){
            defaultHint("密码格式错误");
            return
        }

        if(!typtwo){
            defaultHint("密码格式错误");
            return
        }


        if(!(pone===ptwo)){
            defaultHint("两次密码不一样");
            return
        }

        return;

        ptwo=hex_md5($('#password').val());

            myAjaxFunc({
                url:geturluser+"savePassword",
                type:"post",
                dataType:'json',
                data:{phone:aircraftphone,password:ptwo},
                mySuccess:function(data){

                    if(data.success){

                        defaultHint('设置成功');

                        window.location.href='usercenter.html'

                    }else {
                        if(data.msg==null){
                            defaultHint("保存失败");

                        }else {
                            defaultHint("data.msg");

                        }
                    }
                }
            });
    })





    // 找回密码
    // 找回密码
    // 找回密码
    // 找回密码


    $('#gefindtLogin').click(function () {

        $('.findBox').hide();
        $('.loginBox').show();

    });


    $('#forget').click(function () {

        $('.loginBox').hide();
        $('.findBox').show();

    });





    var getfindCode_=$('#getfindCode');

    var flagfindwangyiCode=false;




    $('#findPhone').bind('input propertychange', function () {

        let telNumber = $("#findPhone").val();
        if (telNumber.length >= 11) {
            var typ = verifyTel(telNumber);
            if (typ) {
                if(!flagRegisterwangyiCode){

                    getwangyiFindCode()

                }

                getfindCode_.hide();
                $('#findwangyicode').show();


            } else {


                defaultHint('请输入正确的手机号码');

                getfindCode_.show();
                $('#findwangyicode').hide();

                clearInterval(findTimeList);
                getfindCode_.text("获取验证码");

                getfindCode_.removeClass('getCodeHui');


            }
        } else {
            getfindCode_.show();
            $('#findwangyicode').hide();

            clearInterval(findTimeList);
            getfindCode_.text("获取验证码");
            getfindCode_.removeClass('getCodeHui');

        }

    });


    getfindCode_.click(function () {
        let findPhoneval = $("#findPhone").val(), typ = verifyTel(findPhoneval);
        if (typ) {
            getwangyiFindCode()
        } else {
            defaultHint('请输入正确的手机号码')
        }
    });


    //智能无感验证
    function getwangyiFindCode(){


        let picTokenAppId_=sessionStorage.getItem('picTokenAppId');

        if (notNull(picTokenAppId_)) {


            var serviceProvider = picTokenAppId_.split(',');
            var service = serviceProvider[0];
            var appid_capthaid = serviceProvider[1];

            /*顶象无感验证*/
            if (service == 'dingxiang') {

                var myCaptcha_login = _dx.Captcha(document.getElementById('c1'), {
                    appId: appid_capthaid,//appId,开通服务后可在控制台中“服务管理”模块获取
                    style: 'popup',
                    customLanguage: {
                        init_inform: '拖动完成拼图，获取验证码', // <-- 初始化时的提示文案
                        slide_inform: '拖动滑块拼图，获取验证码',// <-- 滑块中的提示文案
                        load_fail: '加载失败，<a href="#"style="color: #fd5a00;">请重试</a>',
                        loading: '加载中...',
                        pass_by_server: '验证成功',
                        smart_checking: '智能检测环境安全中……',
                        verify_fail: '验证失败',
                        verifying: '验证中……',

                    },
                    success: function (token) {
                        myCaptcha_login.hide();
                        getPicToken = token;
                        if (notNull(getPicToken)) {

                            getpicTokenMessageCode(telNumber, getPicToken, service)

                        } else {
                            showMassage = "获取getPicToken失败";
                            showUserMessage(showMassage)
                        }
                    }
                });
                myCaptcha_login.show();
            }


            /*网易无感*/
            if (service == 'wangyi') {


                initNECaptcha({
                    captchaId: appid_capthaid,
                    element: '#findwangyicode',
                    mode: 'float',
                    width: 320,
                    onReady:function (instance) {
                        // 初始化成功
                        $('.yidun_intelli-text').text('点击获取验证码').css({'line-height':"46px",'color':'#ff6f6e'});
                        $('.yidun_intelli-control').css({
                            height:'48px',
                        });

                        flagfindwangyiCode=true;


                    },
                    onVerify: function (err, data) {

                        if (!err) {
                            getPicToken = data.validate;

                            find_getpicTokenMessageCode(getPicToken, service);

                            flagfindwangyiCode=false;


                        }
                    }
                },  function onerror(err) {
                    console.log(err)
                    // 验证码初始化失败处理逻辑，例如：提示用户点击按钮重新初始化
                })


            }

        }
        else {
            getfindCode_.removeClass('sendBg').removeAttr('disabled');
            getfindCode_.show();

        }

    }

    getwangyiFindCode();

    var findTimeList;
    //倒计时
    function findCountdown() {
        getfindCode_.show();
        $('#findwangyicode').hide();

        clearInterval(findTimeList);

        var i = 60;
        findTimeList = setInterval(function () {
            i--;

            getfindCode_.text("" + i + "S后重发");
            if (i < 0) {
                clearInterval(findTimeList);
                getfindCode_.text("获取验证码");
                getwangyiFindCode()

                getfindCode_.hide();
                $('#findwangyicode').show();

                getfindCode_.removeClass('getCodeHui').removeAttr('disabled');


            }
        }, 1000);

    }

    function  find_getpicTokenMessageCode( getPicToken, service) {

        let findCode = $('#findPhone').val();


        myAjaxFunc({
            url: geturluser + "getIdentifyCodeInChangePassword",
            type: "post",
            dataType: 'json',
            data: {phone: findCode, picToken: getPicToken, serviceProvider: service},

            mySuccess: function (data) {

                if (data.success) {


                    if (data.msg == null) {


                        defaultHint('发送成功，请注意短信消息');
                    } else {

                        defaultHint(data.msg);

                    }


                } else {
                    if (data.msg == null) {

                        defaultHint('发送失败');

                    } else {
                        defaultHint(data.msg);
                    }

                }

                findCountdown()
            }
        });
    }

    /*找回密码*/
    $('#findNext').click(function () {
        var telNumber = $("#findPhone").val(),
            checkCode = $("#findCode").val();
        var typone = verifyTel(telNumber);


        if(isNull(telNumber)){
            defaultHint("请输入手机号码");
            return
        }


        if(isNull(checkCode)){
            defaultHint("请输入验证码");
            return
        }

        if(!typone){
            defaultHint("手机号码错误");
            return
        }
        myAjaxFunc({
            url: geturluser + "isIdentifyCodeSuccess",
            type: "post",
            dataType: 'json',
            data: {phone: telNumber, identifyCode: checkCode},
            mySuccess: function (data) {
                if (data.success) {

                    localStorage.setItem('pctoken', Base64.encode(data.data.token));

                    setUserInfo(data.data.user);

                    var time = new Date();        //获取当前日(1-31)
                    localStorage.setItem('time', time.getDate());

                    setTimeout(function () {
                        window.location.href = 'usercenter.html?settype=find'
                    }, 100)


                } else {
                    if (data.msg == null) {
                        defaultHint('验证码失效');
                    } else {
                        defaultHint(data.msg);

                    }

                }
            }
        });

    });




});